# styles.py
from tkinter import ttk


def apply_styles():
    """应用样式"""
    style = ttk.Style()

    # 使用更现代的主题
    style.theme_use('clam')

    # 配置基础颜色
    style.configure("White.TFrame", background="#ffffff")

    # 配置主框架和背景
    style.configure('TFrame', background='#f5f7fa')
    style.configure('TLabelframe', background='#f5f7fa', bordercolor='#d1d8e0')
    style.configure('TLabelframe.Label', background='#f5f7fa', foreground='#2c3e50',
                    font=('Microsoft YaHei', 10, 'bold'))

    # 配置按钮样式 - 蓝色按钮
    style.configure('Accent.TButton',
                    background='#4e9eff',
                    foreground='white',
                    font=('Microsoft YaHei', 10, 'bold'),
                    borderwidth=0,
                    focusthickness=0,
                    focuscolor='none',
                    padding=8)

    style.map('Accent.TButton',
              background=[('pressed', '#3a7de6'), ('active', '#6fa8e7')],
              foreground=[('pressed', 'white'), ('active', 'white')])

    # 配置普通按钮
    style.configure('TButton',
                    background='#e0e7ff',
                    foreground='#4e9eff',
                    font=('Microsoft YaHei', 9),
                    borderwidth=1,
                    relief='solid',
                    padding=5)

    style.map('TButton',
              background=[('pressed', '#d1d8e0'), ('active', '#e0e7ff')])

    # 配置标签样式
    style.configure('TLabel',
                    font=('Microsoft YaHei', 10),
                    background='#f5f7fa',
                    foreground='#2c3e50')

    # 配置标题标签
    style.configure('Title.TLabel',
                    font=('Microsoft YaHei', 16, 'bold'),
                    foreground='#4e9eff')

    # 配置输入框样式
    style.configure('TEntry',
                    font=('Microsoft YaHei', 10),
                    fieldbackground='white',
                    bordercolor='#d1d8e0',
                    lightcolor='#d1d8e0',
                    darkcolor='#d1d8e0',
                    padding=5)

    # 配置下拉框样式
    style.configure('TCombobox',
                    font=('Microsoft YaHei', 10),
                    fieldbackground='white',
                    arrowcolor='#4e9eff',
                    selectbackground='#e0e7ff',
                    padding=5)

    # 配置表格样式
    style.configure('Treeview',
                    background='white',
                    foreground='#333333',
                    fieldbackground='white',
                    rowheight=25,
                    font=('Microsoft YaHei', 10),
                    bordercolor='#d1d8e0',
                    lightcolor='#d1d8e0',
                    darkcolor='#d1d8e0')

    style.configure('Treeview.Heading',
                    background='#e0e7ff',
                    foreground='#2c3e50',
                    font=('Microsoft YaHei', 10, 'bold'),
                    relief='flat',
                    padding=5)

    style.map('Treeview.Heading',
              background=[('active', '#d1e0ff')])

    # 配置状态栏样式
    style.configure('Status.TLabel',
                    background='#e0e7ff',
                    foreground='#4e9eff',
                    font=('Microsoft YaHei', 9),
                    padding=5,
                    relief='sunken')

    # 配置选项卡样式 - 改进版本
    style.configure('TNotebook',
                    background='#f5f7fa',
                    borderwidth=0)  # 去除Notebook的边框

    style.configure('TNotebook.Tab',
                    background='#e0e7ff',
                    foreground='#4e9eff',
                    font=('Microsoft YaHei', 10),
                    padding=(15, 8),  # 增加内边距
                    borderwidth=1,
                    relief='solid',
                    lightcolor='#d1d8e0',
                    darkcolor='#d1d8e0')

    style.map('TNotebook.Tab',
              background=[('selected', '#4e9eff'), ('active', '#d1e0ff')],
              foreground=[('selected', 'white')],
              relief=[('selected', 'solid'), ('!selected', 'solid')])

    # 添加选项卡分隔线
    style.layout('TNotebook.Tab', [
        ('Notebook.tab', {
            'sticky': 'nswe',
            'children': [
                ('Notebook.padding', {
                    'side': 'top',
                    'sticky': 'nswe',
                    'children': [
                        ('Notebook.focus', {
                            'side': 'top',
                            'sticky': 'nswe',
                            'children': [
                                ('Notebook.label', {'side': 'top', 'sticky': ''}),
                            ]
                        })
                    ]
                })
            ]
        })
    ])


    style.configure('Vertical.TScrollbar',
                    background='#d1d8e0',
                    troughcolor='#f5f7fa',
                    gripcount=0,
                    arrowsize=12)
    style.map('Vertical.TScrollbar',
              background=[('pressed', '#aeb5c0'), ('active', '#c0c7d0')])

    # 配置分组框样式
    style.configure('Group.TFrame',
                    background='#ffffff',
                    borderwidth=1,
                    relief='solid',
                    bordercolor='#d1d8e0')

    # 配置操作按钮组
    style.configure('Operation.TFrame',
                    background='#e0e7ff',
                    padding=10,
                    borderwidth=1,
                    relief='solid',
                    bordercolor='#d1d8e0')